Home

Computer science

'

please show code

Question

Write CREATE TABLE and ALTER TABLE statements that:

  1. Implement the entity as a new phone table.
  2. Implement the has relationships as foreign keys in the Sakila customer, staff, and store tables.
  3. Remove the existing phone column from the Sakila address table.

Step 2 requires adding a foreign key constraint to an existing table. Example:\r\n\r\n\r\nALTER TABLE customer\r\nADD FOREIGN KEY (phone_id) REFERENCES phone(phone_id)\r\nON DELETE SET NULL\r\nON UPDATE CASCADE;


Specify data types as follows:

  • phone_id, phone_number, and country_code have data type INT.
  • phone_type has data type VARCHAR(12) and contains strings like \'Home\', \'Mobile\', and \'Other\'.


Apply these constraints:

  • NOT NULL constraints correspond to coordinates on the diagram above.
  • Foreign key actions are SET NULL for delete rules and CASCADE for update rules.
  • Specify a suitable column as the phone table primary key.

\r\n\r\n\r\n\r\n\r\n\r\n



'

Answer